package com.snoweagle.core;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

public class DefaultLogService implements LogService {

    Logger logger = LoggerFactory.getLogger(getClass());
    @Override
    public void saveLog(Log log) {
        logger.info(log.toString());
    }

    @Autowired
    private LogProtperties logProtperties;
    @Override
    public String getCurrentName() {
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        Object username = requestAttributes.getRequest().getSession().getAttribute(logProtperties.getUserName());
        return username == null ? null : username.toString();
    }
}
